<!doctype html>
<html>
<head>
<title>编辑游客信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="assets/css/amazeui.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/dcalendar.picker.css"/>
<style>
	.am-ucheck-checkbox:checked + .am-ucheck-icons, .am-ucheck-radio:checked + .am-ucheck-icons {
    color: #69bae0;
}
.am-ucheck-checkbox:hover:not(.am-nohover):not(:disabled) + .am-ucheck-icons, .am-ucheck-radio:hover:not(.am-nohover):not(:disabled) + .am-ucheck-icons {
    color: #69bae0;
}
#list_right:after{
	content:"▼";
	position: relative;
	left:2rem;
}
</style>
</head>
<body>
<!--<div id="content_ul">
    	<ul id="id_select">
	    	<li id="sfz">身份证</li>
	    	<li id="ga">港澳通行证</li>
	    	<li id="passport">护照</li>
	    	<li id="tw">台湾通行证</li>
   	 	</ul>
  </div>-->
<div class="containter">
  <header data-am-widget="header" class="am-header am-header-default">
    <div class="am-header-left am-header-nav">
        <a href="javascript:;"onClick="javascript :history.back(-1);">
          <img src="assets/images/left.png">
        </a>
    </div>
    <h1 class="am-header-title" style="margin:0 14%">
      编辑游客信息
    </h1>
  </header>
  <div style="height: 4rem; width: 100%;"></div>
  <div class="message">
    <form action="">
    <ul class="list">
      <li>
          <img src="assets/images/a14.png"><span>姓名</span><input type="text" id="real_name" value="" maxlength="6"/>
      </li>
      
       <li>
          <img src="assets/images/a10.png">
          <span>证件类型</span>
          <div style="display: inline-block;width:40.8%;position: relative;">
          	<div id="list_right" id_type="sfz">
	          	<b id="id_type">身份证</b>
	          </div>
	         <ul id="id_select" style="z-index:1000">
			    	<!--<li id="sfz">身份证</li>
			    	<li id="ga">港澳通行证</li>
			    	<li id="passport">护照</li>
			    	<li id="tw">台湾通行证</li>-->
		   	 </ul>
          </div>
          
          
      </li>
      <li>
          <img src="assets/images/a10.png"><span>证件号码</span><input type="text" id="id_number" maxlength="18"/>
      </li>
      <li>
          <img src="assets/images/a7.png"><span>性别</span>
          <label class="am-radio M" sex="M">
            <input type="radio" name="radio1" value="" data-am-ucheck class="inpt_box"/>
            男
          </label>
          <label class="am-radio F" sex="F" style="margin-right:1rem">
            <input class="sex_inpt" type="radio" name="radio1" value="" data-am-ucheck class="inpt_box"/>
            女
          </label>
          <!--<label class="am-radio U" sex="U">
            <input class="sex_inpt" type="radio" name="radio1" value="" data-am-ucheck class="inpt_box"/>
            保密 
          </label>-->
      </li>
    </ul>
    <ul class="list">
      <li>
          <img src="assets/images/a8.png"><span>出生日期</span><input id="birthday" readonly="true" onkeydown="return false" style=" height:2.4rem;display: inline-block;background-color:inherit;" type="text" class="am-form-field" placeholder="" data-am-datepicker/>
      </li>
      <li>
          <img src="assets/images/a9.png"><span>手机号码</span><input type="text" id="phone_num" maxlength="11"/>
      </li>
    </ul>
    </form>
    <p><img src="assets/images/a122.png" alt="">身份证、港澳通行证、护照至少必填其中一项</p>
    <div class="temp_chk" style="display: flex;justify-content: space-around;align-items: baseline;">	
	    <button style="background: #ff7cad; color: #fff;width:70%" class="baocun">保存</button>
	    <label class="am-checkbox">
	    	<input class="temp am-ucheck-checkbox check_inpt" name="radio2" type="checkbox" value="temp" data-am-ucheck>(临时)
	    	<span class="am-ucheck-icons">
	    		<i class="am-icon-unchecked"></i>
	    		<i class="am-icon-checked"></i>
	    	</span>
	    </label>
    </div>
    
  </div>
</div>
<div id="toast" style="top:-9rem"></div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/dcalendar.picker.js"></script>
<script src="assets/js/allUse.js"></script>
<!--6.13.常旅资料修改-->
		<script type="text/javascript">
//			$(".baocun").click(function() {
//				var birthday=$("#birthday").val().split("/").join("-")
//				
//				
//				$.ajax({
//					type: "post",
//					url: url_enter+"/api/modify_peer_info",
//					headers: {
//						"User-Token":token,
//						"Os":ios_Andriod,
//						"Device-Id":"",
//						"Screen":wh,
//						"Content-Type": "application/x-www-form-urlencoded"
//					},
//					data: {
//						"req":{
//							"peer_id":"",
//							"phone_num":$("#phone_num").val(),
//							"real_name":$("#real_name").val(),
//							"gender":"M",
//							"birthday":birthday,
//							"card_type":"sfz",
//							"card_no":$("#id_card").val()
//						}
//					},
//					success: function(data, status, xhr) {
//						//无返回
//						console.log(data);
//						
//					},
//					error: function(xhr, status, thrown) {
//						console.log(xhr);
//					}
//				});
//			});
			$(document).ready(function(){
				var regn = /^[0-9]*$/
				$("#phone_num").on("keyup",function(){
					if(!regn.test($(this).val())){
						$(this).val($(this).val().substring(0,$(this).val().length-1))
					}
				});
				$.ajax({
					type: "get",
					url: url_enter+"/api/get_identity",
					headers: headers,
                    success: function(data) {
                    	$('#id_select').append('<li id="sfz">'+data.data.tourist_list[0].ity_name+'</li><li id="ga">'+data.data.tourist_list[1].ity_name+'</li><li id="passport">'+data.data.tourist_list[2].ity_name+'</li><li id="tw">'+data.data.tourist_list[3].ity_name+'</li>')
                    },
                    error: function(xhr, status, thrown) {
						console.log(xhr);
					}
                   
        		})
//				$("#list_right").click(function(event){
//					
//						console.log(2)
//						
//					$("#content_ul").css('display',''+$("#content_ul").css('display')=="none" ? "block" : "none"+'')
//						$("#id_select").click(function(){
//							var evt=event || window.event;
//								if(evt.attachEvent){
//									evt.cancelBubble=true;	
//								}else{
//									console.log(3)
//									evt.stopPropagation();	
//								}
//								console.log(0)
//							$("#content_ul").click(function(event){
//							var evt=event || window.event;
//								if(evt.attachEvent){
//									evt.cancelBubble=true;	
//								}else{
//									evt.stopPropagation();	
//								}
//							console.log(1)
//						})
//						})
//					
//				})
//				var real_name=$("")
					//以下 证件列表展开
//					var box=document.getElementsByClassName("box")[0];
//					var p=box.getElementsByTagName("p")[0];
//					var ul=box.getElementsByTagName("ul")[0];
//					var list=ul.getElementsByTagName("li");
						var listRight=document.getElementById("list_right");
						var idSelect=document.getElementById("id_select");
						var li=idSelect.getElementsByTagName("li");
					listRight.onclick=function(event){
						idSelect.style.display= idSelect.style.display=="block" ? "none" : "block";	
						var evt=event || window.event;
						if(evt.attachEvent){
							evt.cancelBubble=true;	
						}else{
							evt.stopPropagation()	
						}
						for(var i=0;i<li.length;i++){						
							li[i].onclick=function(){
								listRight.innerHTML=this.innerHTML	
								listRight.setAttribute("id_type",this.getAttribute("id"))
							}
						}
					}
					document.onclick=function(){
						idSelect.style.display="none"	
					}
					//输入身份证自动填充出生日期
					if(listRight.getAttribute('id_type')=="sfz"){
						$('#id_number').on('input',function(){
							if($('#id_number').val().length==18){
								var id_num=$('#id_number').val();
								birth=id_num.substring(6, 10) + "-" + id_num.substring(10, 12) + "-" + id_num.substring(12, 14);
								$('#birthday').val(birth);
								if((id_num.substring(16, 17)%2)==0){
									$(".F input[name=radio1]").prop('checked',true);
								}else{
									$(".M input[name=radio1]").prop('checked',true);
								}
							}
						})
					}
					//以上 证件列表展开
				if(GetQueryString("from")=="tourist"||GetQueryString("from")=="material_add"){//添加游客信息
					if(GetQueryString("from")=="material_add"){
						$('.temp_chk label').css('display','none');
					}
					$(".am-header-title").html("添加游客信息");
					$(".baocun").html("添加");
					var flagthis=true;
					$(".baocun").click(function(){
						var sex=$('input[name="radio1"]:checked').parent().attr("sex");
						console.log(sex);
						if(sex===undefined){
							sex="U"
						}
					var birthday=$("#birthday").val().split("/").join("-");
					var car_type=$("#list_right").attr("id_type");
					var rxPhone = /^1[3|4|5|7|8][0-9]{9}$/;
					if(!$("#real_name").val()){
						showToast("请输入姓名");
						return;
					}else if(!$("#phone_num").val()){
						showToast("请输入手机号");
						return;
					}else if(!$("#id_number").val()){
						showToast("请输入证件号号");
						return;
					}else if(!rxPhone.test($("#phone_num").val())){
						showToast("手机号码有误");
						return;
					}else if(!$("#birthday").val()){
						showToast("请填写出生日期");
						return;
					}else if(!flagthis){
						return;
					}
					flagthis=true;
					var req='{"phone_num":"'
					+$("#phone_num").val()+'","real_name":"'
					+$("#real_name").val()+'","gender":"'
					+sex+'","birthday":"'
					+birthday+'","card_type":"'
					+car_type+'","card_no":"'
					+$("#id_number").val()+'"}'
//							console.log(req)
//							console.log($(".am-nohover").attr("sex"))
//							console.log(car_type)
//							console.log($("#list_right").attr("id_type"))
					if($('.temp').prop("checked")){
						var r=sessionStorage.getItem('req');
						var i;
						if(r){
							i=''+JSON.parse(r).length;
						}else{
							i=0;
							r='[]';
						} 
						var r_name=$("#real_name").val();
						var tem_req='[{"phone_num":"'
					+$("#phone_num").val()+'","real_name":"'
					+r_name+'","gender":"'
					+sex+'","birthday":"'
					+birthday+'","card_type":"'
					+car_type+'","card_no":"'
					+$("#id_number").val()+'","peer_id":"'+'t'+i+'"}]'
						var re=JSON.parse(r).concat(JSON.parse(tem_req));
							re=JSON.stringify(re);
							console.log(re);
						sessionStorage.setItem('req',re);
						window.location.href=document.referrer
					}else{
						$.ajax({
								type:"post",
								url:url_enter+"/api/add_peer",
								headers: headers,
								data:{
									"req":encodeURIComponent(req)
								},
								success:function(data){
									flagthis=true
									console.log(data)
									if(data.result===1){
//										alert("添加成功")
										
										
										window.location.href=document.referrer
									}else{
										alert(data.message)
									}
								},
								error:function(){
									
								}
							})
					}
						})
				}else if(sessionStorage.getItem("form_peer_id")||GetQueryString("peer_id")){//修改常旅信息
//					$(".sex_inpt").removeAttr("checked")
					if(GetQueryString("peer_id")){
						$('.temp_chk label').css('display','none');
						var i=GetQueryString("peer_id").substr(1);
						var t_req=JSON.parse(sessionStorage.getItem('req'));
						$("#real_name").val(t_req[i].real_name);
								if(t_req[i].gender=="U"){
									
								}else{
									$('.'+t_req[i].gender+'').find($("input[name='radio1']")).attr("checked","checked");
								}
								
								$("#birthday").val(t_req[i].birthday);
								$("#birthday").change(function(){
									$("#birthday").val($(this).attr("value"))
								})
								$("#phone_num").val(t_req[i].phone_num);
								var id_types;
								var id_inners;
								switch(t_req[i].card_type){
									case "ga":
									id_types="ga";
									id_inners="港澳通行证";break;
									case "sfz":
									id_types="sfz";
									id_inners="身份证";break;
									case "tw":
									id_types="tw";
									id_inners=" 台湾通行证";break;
									case "passport":
									id_types="passport";
									id_inners="护照";break;
								};
								$("#list_right").attr("id_type",id_types);
								$("#list_right").html(id_inners);
								$("#id_number").val(t_req[i].card_no);
								var flagthis=true
								$(".baocun").click(function(){//编辑游客信息
									var rxPhone = /^1[3|4|5|7|8][0-9]{9}$/;
									var sex=$('input[name="radio1"]:checked').parent("label").attr("sex");
									if(sex===undefined){
										sex="U"
									};
									var req={"peer_id":'t'+i,"phone_num":""+$("#phone_num").val()+"","real_name":""+$("#real_name").val()+"","gender":""+sex+"","birthday":""+$("#birthday").val()+"","card_type":""+$("#list_right").attr("id_type")+"","card_no":""+$("#id_number").val()+""}
									t_req[i]=req;
//									var req='{"peer_id":'
//									+i+',"phone_num":"'
//									+$("#phone_num").val()+'","real_name":"'
//									+$("#real_name").val()+'","gender":"'
//									+sex+'","birthday":"'
//									+$("#birthday").val()+'","card_type":"'
//									+$("#list_right").attr("id_type")+'","card_no":"'
//									+$("#id_number").val()+'"}';
									if(!$("#real_name").val()){
										showToast("请输入姓名");
										return;
									}else if(!$("#phone_num").val()){
										showToast("请输入手机号");
										return;
									}else if(!$("#id_number").val()){
										showToast("请输入证件号号");
										return;
									}else if(!rxPhone.test($("#phone_num").val())){
										showToast("手机号码有误");
										return;
									}else if(!flagthis){
										return;
									}else{
										sessionStorage.setItem('req',JSON.stringify(t_req));
										window.location.href=document.referrer
									}
								})
									
					}else{
						$('.temp_chk label').css('display','none');
						console.log(sessionStorage.getItem("form_peer_id"))
						$.ajax({//获取常旅详情
							type:"get",
							url:url_enter+"/api/get_peer_detail",
							headers:{
								"User-Token":token,
								"Os":ios_Andriod,
								"Device-Id":"",
								"Screen":wh,
								"Content-Type": "application/x-www-form-urlencoded"
							},
							data:{
								"peer_id":sessionStorage.getItem("form_peer_id")
							},
							success:function(data){
								if(data.result===1){
									console.log(data);
									$("#real_name").val(data.data.real_name);
									if(data.data.gender=="U"){
										
									}else{
										$('.'+data.data.gender+'').find($("input[type='radio']")).attr("checked","checked");
									}
									
									$("#birthday").val(data.data.birthday);
									$("#birthday").change(function(){
										$("#birthday").val($(this).attr("value"))
									})
									$("#phone_num").val(data.data.phone_num);
									var id_types;
									var id_inners;
									switch(data.data.card_type){
										case "ga":
										id_types="ga";
										id_inners="港澳通行证";break;
										case "sfz":
										id_types="sfz";
										id_inners="身份证";break;
										case "tw":
										id_types="tw";
										id_inners=" 台湾通行证";break;
										case "passport":
										id_types="passport";
										id_inners="护照";break;
									};
									$("#list_right").attr("id_type",id_types);
									$("#list_right").html(id_inners);
									$("#id_number").val(data.data.card_no);
									var flagthis=true
									$(".baocun").click(function(){//编辑游客信息
										var rxPhone = /^1[3|4|5|7|8][0-9]{9}$/;
										var sex=$('input[type="radio"]:checked').parent("label").attr("sex");
										if(sex===undefined){
											sex="U"
										};
										var req={"peer_id":sessionStorage.getItem("form_peer_id"),"phone_num":""+$("#phone_num").val()+"","real_name":""+$("#real_name").val()+"","gender":""+sex+"","birthday":""+$("#birthday").val()+"","card_type":""+$("#list_right").attr("id_type")+"","card_no":""+$("#id_number").val()+""}
										var req='{"peer_id":'
										+sessionStorage.getItem("form_peer_id")+',"phone_num":"'
										+$("#phone_num").val()+'","real_name":"'
										+$("#real_name").val()+'","gender":"'
										+sex+'","birthday":"'
										+$("#birthday").val()+'","card_type":"'
										+$("#list_right").attr("id_type")+'","card_no":"'
										+$("#id_number").val()+'"}';
										if(!$("#real_name").val()){
											showToast("请输入姓名");
											return;
										}else if(!$("#phone_num").val()){
											showToast("请输入手机号");
											return;
										}else if(!$("#id_number").val()){
											showToast("请输入证件号号");
											return;
										}else if(!rxPhone.test($("#phone_num").val())){
											showToast("手机号码有误");
											return;
										}else if(!flagthis){
											return;
										}
										
										flagthis=false;
										$.ajax({
											type: "post",
											url: url_enter+"/api/modify_peer_info",
											headers: {
												"User-Token":token,
												"Os":ios_Andriod,
												"Device-Id":"",
												"Screen":wh,
												"Content-Type": "application/x-www-form-urlencoded"
											},
											data: {
												"req":encodeURIComponent(req)
											},
											success: function(data, status, xhr) {
												//无返回
												flagthis=true;
												if(data.result===1){
													alert(data.message);
													window.location.href=document.referrer;
												};
												
											},
											error: function(xhr, status, thrown) {
												console.log(xhr);
											}
										});
									})
								};
							},
							error:function(xht){
								console.log(xhr)
							}
						});
						return;
						$.ajax({
							type:"get",
							url:url_enter+"/api/get_peer_detail",
							headers: {
								"User-Token":token,
								"Os":ios_Andriod,
								"Device-Id":"",
								"Screen":wh,
								"Content-Type": "application/x-www-form-urlencoded"
							},
							data:{
								
							},
							success:function(data){
								console.log(data)
								if(data.result===1){
									$("#real_name").val(data.data.real_name);
									$("#birthday").val(data.data.birthday);
									$("#phone_num").val(data.data.phone_num);
									$('label[sex="'+data.data.gender+'"]').find($("input")).attr("checked","checked")
								}
							},
							error:function(xhr, status, thrown){
		        		console.log(xhr);
		        	}
						})
					}

				}
			})
		</script>
		
</body>
</html>